package com.spic.business.violation.supervision.action.controller;

import com.spic.business.common.core.workflow.IWorkFlowService;
import com.spic.business.common.core.workflow.WorkFlowController;
import com.spic.business.violation.supervision.action.domain.ViolationActionInput;
import com.spic.business.violation.supervision.action.service.IViolationActionInputService;
import com.spic.common.core.utils.poi.ExcelUtil;
import com.spic.common.core.web.domain.AjaxResult;
import com.spic.common.core.web.page.TableDataInfo;
import com.spic.common.log.annotation.Log;
import com.spic.common.log.enums.BusinessType;
import com.spic.common.security.annotation.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 违章行为录入Controller
 * 
 * @author spic
 * @date 2021-12-07
 */
@RestController
@RequestMapping("/violation/action")
public class ViolationActionInputController extends WorkFlowController
{
    @Autowired
    private IViolationActionInputService violationActionInputService;

    /**
     * 查询违章行为录入列表
     */
    @PreAuthorize(hasPermi = "business/violation:action:list")
    @GetMapping("/list")
    public TableDataInfo list(ViolationActionInput violationActionInput)
    {
        startPage();
        List<ViolationActionInput> list = violationActionInputService.selectViolationActionInputList(violationActionInput);
        return getDataTable(list);
    }

    /**
     * 查询违章行为录入和违章举报的水印照片列表
     */
    @GetMapping("/getIllegalPhotoWithWatermark")
    public AjaxResult getIllegalPhotoWithWatermark() {
        return AjaxResult.success(violationActionInputService.getPhotoWithWatermark());
    }

    /**
     * 导出违章行为录入列表
     */
    @PreAuthorize(hasPermi = "business/violation:action:export")
    @Log(title = "违章行为录入", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ViolationActionInput violationActionInput) throws IOException
    {
        List<ViolationActionInput> list = violationActionInputService.selectViolationActionInputList(violationActionInput);
        ExcelUtil<ViolationActionInput> util = new ExcelUtil<ViolationActionInput>(ViolationActionInput.class);
        util.exportExcel(response, list, "违章行为录入数据");
    }

    /**
     * 获取违章行为录入详细信息
     */
    @PreAuthorize(hasPermi = "business/violation:action:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(violationActionInputService.selectViolationActionInputById(id));
    }

    /**
     * 新增违章行为录入
     */
    @PreAuthorize(hasPermi = "business/violation:action:add")
    @Log(title = "违章行为录入", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ViolationActionInput violationActionInput)
    {
        return  AjaxResult.success(violationActionInputService.insertViolationActionInput(violationActionInput));
    }
    @GetMapping("tongbao")
    public AjaxResult tongbao()
    {
        return  AjaxResult.success(violationActionInputService.tongbao());
    }

    /**
     * 修改违章行为录入
     */
    @PreAuthorize(hasPermi = "business/violation:action:edit")
    @Log(title = "违章行为录入", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ViolationActionInput violationActionInput)
    {
        return toAjax(violationActionInputService.updateViolationActionInput(violationActionInput));
    }

    /**
     * 删除违章行为录入
     */
    @PreAuthorize(hasPermi = "business/violation:action:remove")
    @Log(title = "违章行为录入", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(violationActionInputService.deleteViolationActionInputByIds(ids));
    }

    @GetMapping("downloadReport/{id}")
    public void  downloadReport(@PathVariable("id") Long id, HttpServletResponse response){
        violationActionInputService.downloadReport(id, response);
    }

    @PutMapping("markViolationImage")
    public void markViolationImage() {
        violationActionInputService.markViolationImage();
    }

    @Override
    protected IWorkFlowService getService() {
        return violationActionInputService;
    }

    @GetMapping("filterDirtyData")
    public AjaxResult filterDirtyData() {
        violationActionInputService.filterDirtyData();
        return AjaxResult.success();
    }

    @GetMapping("createTrain")
    public AjaxResult createTrain() {
        violationActionInputService.createTrain();
        return AjaxResult.success();
    }
}
